package serializeUtil;

import consumer.ConsumerJsonBody;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @author : zGame
 * @version V1.0
 * @Project: rokectmqprac
 * @Package serializeUtil
 * @Description: TODO
 * @date Date : 2022年01月11日 18:45
 */
public class JDKSerialize {
    
    public static byte[] convert2Byte(ConsumerJsonBody obj) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream sOut = null;
        try {
            sOut = new ObjectOutputStream(out);
            sOut.writeObject(obj);
            sOut.flush();
            return out.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static ConsumerJsonBody convert2Obj(byte[] bytes) {
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(bytes);
            ObjectInputStream sin =  new ObjectInputStream(in);
            ConsumerJsonBody obj = (ConsumerJsonBody) sin.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
